package com.jmyd.sharding.controller;

import com.jmyd.sharding.base.dto.KeywordQueryDto;
import com.jmyd.sharding.base.vo.PageBean;
import com.jmyd.sharding.base.vo.Result;
import com.jmyd.sharding.constants.BaseUrlConstants;
import com.jmyd.sharding.domain.dto.SysCouponDto;
import com.jmyd.sharding.domain.dto.SysCouponUpdateDto;
import com.jmyd.sharding.domain.vo.SysCouponVo;
import com.jmyd.sharding.service.ISysCouponService;
import com.jmyd.sharding.service.ISysCouponService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 系统用户优惠券相关接口文档
 *
 * @author samphin
 * @date 2024-6-18 11:11:07
 */
@RestController
@RequestMapping(value = BaseUrlConstants.BASE_ADMIN_USER_COUPON_API_PREFIX)
public class SysCouponController {
    @Resource
    private ISysCouponService sysCouponService;

    /**
     * 保存
     *
     * @param dto
     */
    @PostMapping
    public Result<Boolean> save(@RequestBody SysCouponDto dto) {
        final boolean bl = this.sysCouponService.save(dto);
        return new Result<>(bl);
    }

    /**
     * 修改
     *
     * @param dto
     */
    @PutMapping
    public Result<Boolean> updateById(@RequestBody SysCouponUpdateDto dto) {
        final boolean bl = this.sysCouponService.updateById(dto);
        return new Result<>(bl);
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable Long id) {
        final boolean bl = this.sysCouponService.deleteById(id);
        return new Result<>(bl);
    }

    /**
     * 查看分页列表
     */
    @GetMapping
    public Result<PageBean<SysCouponVo>> paging(KeywordQueryDto queryDto) {
        final PageBean<SysCouponVo> pageBean = this.sysCouponService.paging(queryDto);
        return new Result<>(pageBean);
    }

    /**
     * 查看详情
     */
    @GetMapping("/{id}")
    public Result<SysCouponVo> queryById(@PathVariable Long id) {
        final SysCouponVo vo = this.sysCouponService.queryDetail(id);
        return new Result<>(vo);
    }
}